package com.meetingshow.common.base.service;

import java.util.HashMap;
import java.util.Map;

import com.meetingshow.common.base.dao.model.OrQueryItemList;
import com.meetingshow.common.base.dao.model.QueryStruct;
import com.meetingshow.common.base.dao.model.RelationList;
import com.meetingshow.common.base.service.model.BaseQueryParas;
import com.meetingshow.utils.BaseUtil;

public class BaseQueryParasBuilder {


    
    protected static QueryStruct pageBuilder(QueryStruct queryStruct,BaseQueryParas baseQueryParas)
    {
        if(BaseUtil.objectNotNull(baseQueryParas.getFirstresultno()))
        {
            queryStruct.setFirstResultNo(baseQueryParas.getFirstresultno());
        }
        if(BaseUtil.objectNotNull(baseQueryParas.getResultspergroup()))
        {
            queryStruct.setResultsPerGroup(baseQueryParas.getResultspergroup());
        }
        return queryStruct;
        
    }
    
    protected static QueryStruct builderInit(BaseQueryParas baseQueryParas,QueryStruct queryStruct) throws Exception
    {
        if(BaseUtil.objectNotNull(baseQueryParas)== false &&BaseUtil.objectNotNull(queryStruct) ==  false)
        {
            throw new Exception();
        }
        Map<String, Object> exactMap = queryStruct.getExactMap();
        Map<String, String> mistinessMap = queryStruct.getMistinessMap();
        RelationList relationList = queryStruct.getRelationList();
        RelationList dateList = queryStruct.getDateList();
        OrQueryItemList orQueryItemList = queryStruct.getOrQueryItemList();
        
        if(BaseUtil.objectNotNull(exactMap) == false)
        {
            exactMap = new HashMap<String, Object>();
            queryStruct.setExactMap(exactMap);
        }
        
        if(BaseUtil.objectNotNull(mistinessMap) == false)
        {
            mistinessMap = new HashMap<String, String>();
            queryStruct.setMistinessMap(mistinessMap);
        }
        if(BaseUtil.objectNotNull(relationList) == false)
        {
            relationList = new RelationList();
            queryStruct.setRelationList(relationList);
        }
        if(BaseUtil.objectNotNull(dateList) ==  false)
        {
            dateList = new RelationList();
            queryStruct.setDateList(dateList);
        }
        if(BaseUtil.objectNotNull(orQueryItemList) ==  false)
        {
            orQueryItemList = new OrQueryItemList();
            queryStruct.setOrQueryItemList(orQueryItemList);
        }
        
        
        return queryStruct;
    }
}
